include('shared.lua')

local matLight 		= Material( "sprites/light_ignorez" )

function ENT:Initialize()
	
	self.PixVis = util.GetPixelVisibleHandle()
    
    self.LightAttachment = self:LookupBone("body")
	
	self.BaseClass.Initialize( self )
	
end

function ENT:UpdateHealthPos()
	local BonePos = self:GetBonePosition( self.LightAttachment )
	
	self.HealthBar = self:WorldToLocal( BonePos )
	self.HealthBar.z = 0
end

function ENT:Think()
	
	if self:Building() then
	
		local Progress = self:GetProgress()
		
		self:SetPoseParameter("blendstates", 65 - Progress * 65  )
	end
	
	self.BaseClass.Think( self )
	
end

function ENT:GetLightColor( visible )

	if self:Building() then
		return Color(255,0,0, 255 * visible)
	end
	
	return Color(0,255,0, 255 * visible)

end

function ENT:Draw()
	
	local LightPos = self:GetBonePosition( self.LightAttachment ) + Vector(0,0,0.1)
	local Visibile	= util.PixelVisible( LightPos, 4, self.PixVis )
    
	self.BaseClass.Draw( self )
	
    if Visibile then
		render.SetMaterial( matLight )
		render.DrawSprite( LightPos , 32, 32, self:GetLightColor( Visibile ) )
	end

end

function ENT:DrawTranslucent()

	self.BaseClass.DrawTranslucent( self )
	
end